package scau.hotel.hotel_service.service.impl;

import scau.hotel.hotel_service.entity.RoomTypeDiscount;
import scau.hotel.hotel_service.mapper.RoomTypeDiscountMapper;
import scau.hotel.hotel_service.service.RoomTypeDiscountService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import scau.hotel.hotel_model.controller.RespBean;

import javax.annotation.Resource;
import java.util.List;

/**
 * (RoomTypeDiscount)表服务实现类
 *
 * @author makejava
 * @since 2022-04-07 20:52:35
 */
@Service("roomTypeDiscountService")
public class RoomTypeDiscountServiceImpl implements RoomTypeDiscountService {
    @Resource
    private RoomTypeDiscountMapper roomTypeDiscountMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param roomTypeDiscountId 主键
     * @return 实例对象
     */
    @Override
    public RoomTypeDiscount queryById(Integer roomTypeDiscountId) {
        return this.roomTypeDiscountMapper.queryById(roomTypeDiscountId);
    }

    /**
     * 查询所有行
     *
     * @param roomTypeDiscount 查询条件
     * @return 对象列表
     */
    @Override
    public List<RoomTypeDiscount> queryAll(RoomTypeDiscount roomTypeDiscount){
        return this.roomTypeDiscountMapper.queryAll(roomTypeDiscount);
    }

    /**
     * 分页查询
     *
     * @param roomTypeDiscount 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<RoomTypeDiscount> queryByPage(RoomTypeDiscount roomTypeDiscount, PageRequest pageRequest) {
        long total = this.roomTypeDiscountMapper.count(roomTypeDiscount);
        return new PageImpl<>(this.roomTypeDiscountMapper.queryAllByLimit(roomTypeDiscount, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param roomTypeDiscount 实例对象
     * @return 实例对象
     */
    @Override
    public RespBean insert(RoomTypeDiscount roomTypeDiscount) {
        this.roomTypeDiscountMapper.insert(roomTypeDiscount);
        return RespBean.success();
    }

    /**
     * 修改数据
     *
     * @param roomTypeDiscount 实例对象
     * @return 实例对象
     */
    @Override
    public RespBean update(RoomTypeDiscount roomTypeDiscount) {
        this.roomTypeDiscountMapper.update(roomTypeDiscount);
        return RespBean.success();
    }

    /**
     * 通过主键删除数据
     *
     * @param roomTypeDiscountId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer roomTypeDiscountId) {
        return this.roomTypeDiscountMapper.deleteById(roomTypeDiscountId) > 0;
    }
}
